#include <stdio.h>
#define N 2010
int m[N][N];
char s[N];
int main()
{
	int i, j, k, l, r, c, q, pi, pj, pr;
	long long a;
	for(scanf("%d%d", &r, &c), i=0; i<r; i++)
		for(scanf("%s", s), j=0; j<c; m[i][j+1]=m[i][j]+s[j]-'0', j++);
	for(a=0, pi=-1, pj=-1, pr=-1, scanf("%d", &q); q--; pi=i, pj=j, pr=r, a+=c)
	{
		scanf("%d%d%d", &i, &j, &r); i--; j--;
		if(i!=pi || j!=pj || r!=pr)
			for(c=m[i][j+r+1]-m[i][j-r], l=r, k=1; k<=r; c+=m[i+k][j+l+1]-m[i+k][j-l]+m[i-k][j+l+1]-m[i-k][j-l], k++)
				for(; k*k+l*l>r*r; l--);
	}
	printf("%lld\n", a);
	return 0;
}